package com.tyhy.program.cbc.mobileapi.redis.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;

import cn.hutool.core.util.ObjectUtil;

/**
 * PublishController
 *
 * @author ycb
 * 2021年02月18日
 */
@RestController
@RequestMapping("/cbc/common/websocket")
public class PublishController {

    @Autowired
    private PublishService publishService;

    /**
     * 发布websocket消息控制类
     *
     * @return
     * @since 2021-02-18
     * 版本历史:
     * Date         Author         Description
     * ---------------------------------------------------------*
     * 2021-02-18    yaochengbin         初始创建
     */
    @RequestMapping("/sendMessage")
    public void sendMessage(@RequestBody String requestStr) {
        JSONObject jsonParam = JSONObject.parseObject(requestStr);
        //获取渠道
        Object channel = jsonParam.get("channel");
        //获取推送消息
        Object message = jsonParam.get("message");
        if (ObjectUtil.isNotEmpty(channel) && ObjectUtil.isNotEmpty(message)){
            //推送消息
            publishService.publishMessge(channel.toString(), message);
        }
    }
}
